<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	    		xmlns:ui="http://java.sun.com/jsf/facelets"
	  			xmlns:h="http://java.sun.com/jsf/html"
	  			xmlns:f="http://java.sun.com/jsf/core"                
                xmlns:cs="http://myfaces.apress.com/custom"
				template="/WEB-INF/layouts/standard.xhtml"
				xmlns:a4j="http://richfaces.org/a4j"
				xmlns:rich="http://richfaces.org/rich"
				xmlns:bf="http://www.bssmanager.com/jsf"
				xmlns:c="http://java.sun.com/jstl/core" 
				xmlns:fn="http://www.bss.com/functions">
				
	<ui:define name="formheader">
		<h2>Search</h2>
		<style>
			
	        .even-row {
	        background-color: #FCFFFE;
	        }
	 
	        .odd-row {
	        background-color: #ECF3FE;
	        }
	 
	        .active-row {
	        background-color: #FFEBDA !important;
	        cursor: pointer;
	        }
	        
	        td {
	        	vertical-align: top;
	        } 
   
		
		</style>
	</ui:define>
	
	<ui:define name="content">
	
			<h:messages errorClass="errors" style="color:#ff1111" />
			
			<h:form id="searchForm" prependId="false">					
				
				<h:inputHidden id="queryId" value="#{searchController.query}"/>
				
				<rich:panel style="border:0" styleClass="norender">
					<h:panelGrid columns="2">
						<rich:panel>
							<f:facet name="header">
								<h:outputText value="Standard Search"/>
							</f:facet>
							<rich:dataList value="#{fn:call(fn:call(searchController,'getMessage','query.ids'),'split',',')}" var="qq">
								<h:commandLink value="#{fn:call(searchController,'getMessage',fn:concat('query.',fn:concat(qq,'.title')))}" 
									action="#{searchController.select}" onclick="showLoading();document.getElementById('queryId').value='#{qq}';" />
							</rich:dataList>
						</rich:panel>
						<h:panelGrid >
							<rich:panel>
								<f:facet name="header">
									<h:outputText value="Advanced Check-in Search"/>
								</f:facet>
								<h:panelGrid columns="2">
									<h:outputLabel value="Checked-in Date 1:"/>
									<h:inputText value="#{searchController.advancedSearchParam.date1}"/>	
									<h:outputLabel value="Checked-in Date 2:"/>
									<h:inputText value="#{searchController.advancedSearchParam.date2}"/>
								</h:panelGrid>
								<div align="center">
									<h:commandButton value="Submit" action="#{searchController.select}" 
										onclick="showLoading();document.getElementById('queryId').value='advancedSearch';" />
								</div>
							</rich:panel>
							<rich:panel styleClass="noprint" style="width:100%"  >
										<f:facet name="header">
											<h:outputText styleClass="noprint" value="Search Patient"/>
										</f:facet>
										
								<h:panelGroup >
									<bf:patientSelector controller="#{searchController}" selectMethod="selectPatient" reRender="selectedPatients1"
								notFoundMessage="Patient not found" oncomplete="document.getElementById('dPanel').style.display='none'; document.getElementById('ppat').focus();"/>
												</h:panelGroup>
							
							</rich:panel>
						</h:panelGrid>
					</h:panelGrid>
				</rich:panel>								
					
				<rich:panel style="border:0;width:100%;" styleClass="norender">
					<f:facet name="header">
						<h:outputText value="Search Results"/>
					</f:facet>
				</rich:panel>
					
				<div align="center" id="dPanel" >							
				<rich:dataTable value="#{searchController.items}" var="aBean" styleClass="stable" rowKeyVar="rw"   
					rendered="#{not empty searchController.query}" >
					<f:facet name="header">
						<h:outputText value="#{fn:call(searchController,'getMessage',fn:concat('query.',fn:concat(searchController.query,'.title')))}"/>
					</f:facet>
					<rich:column>
						<f:facet name="header">
							<h:outputText value="S/N"/>
						</f:facet>
						<h:outputText value="#{rw+1}"/>
					</rich:column>
					<c:forEach items="#{fn:split(fn:call(searchController,'getMessage',fn:concat('query.',fn:concat(searchController.query,'.columns'))),',')}" var="col">
						<rich:column>
							<f:facet name="header">
								<h:outputText value="#{fn:split(col,':')[0]}"/>
							</f:facet>
							<h:outputText value="#{fn:format(fn:split(col,':')[2],fn:findAttribute(aBean, fn:split(col,':')[1]),fn:split(col,':')[3])}"/>							
						</rich:column>						
					</c:forEach>
				</rich:dataTable>
			    </div>
			    <rich:jQuery selector=".stable tr:odd" query="addClass('odd-row')" />
			    <rich:jQuery selector=".stable tr:even" query="addClass('even-row')" />
			    <rich:jQuery selector=".stable tr" event="mouseover" query="addClass('active-row')" />
			    <rich:jQuery selector=".stable tr" event="mouseout" query="removeClass('active-row')" />
			    
			    
			    
			    
			    <rich:panel id="selectedPatients1" style="border:0;width:100%; display:#{empty searchController.patient ? 'none':'block'}"  >
									<f:facet name="header">
										<h:outputText styleClass="noprint" value="Patient"/>										
									</f:facet>
									<h:panelGrid columns="2">
										<h:panelGroup >											
											<h:graphicImage url="/bss/images/saved?id=#{searchController.patient.id}"/>																	
										</h:panelGroup>
										<h:panelGrid columns="2">	
											<h:outputLabel value="Patient ID:" />
											<h:outputText value="#{searchController.patient.id}"/>		
											<h:outputLabel value="Name:" />
											<h:outputText value="#{searchController.patient.firstName} #{searchController.patient.middleName} #{searchController.patient.lastName}"/>
											<h:outputLabel value="Address:" />
											<h:panelGroup >											
												<h:outputText value="#{searchController.patient.place}" converter="#{placeConverter}"/>
												<h:outputLabel value=", " />
												<h:outputText value="#{searchController.patient.state}" converter="#{stateConverter}" />
												<h:outputLabel value=", " />
												<h:outputText value="#{searchController.patient.country}" converter="#{countryConverter}" />												
											</h:panelGroup>
											<h:outputLabel value="DateOfBirth:" />
											<h:outputText value="#{searchController.patient.dateOfBirth}"/>
											<h:outputLabel value="Sex:" />
											<h:outputText value="#{searchController.patient.sex == 'M' ? 'Male' : 'Female'}"/>							
											<h:outputLabel value="ID Card Type:"/>
											<h:outputText value="#{searchController.patient.idCardType}" converter="#{idCardTypeConverter}" />
											<h:outputLabel value="ID Card Number:" />
											<h:outputText value="#{searchController.patient.idCardNumber}"/>
											<h:outputLabel value="Phone Number:" />
											<h:outputText value="#{searchController.patient.phone}"/>
											<h:outputLabel value="Profession" />
											<h:outputText value="#{searchController.patient.profession}" converter="#{professionConverter}"/>																	
										</h:panelGrid>
										
										
									
											<rich:dataTable width="100%" value="#{fn:asList(searchController.patient.admissions)}" var="aBean" align="center" style="text-align:left">
												<f:facet name="header">
													<h:outputText value="Checkins"/>
													
												</f:facet>									
												<rich:column>
													<f:facet name="header">CheckIn ID</f:facet>
													<h:outputText value="#{aBean.id} "/>
												</rich:column>
												<rich:column>
													<f:facet name="header">CheckIn</f:facet>
													<h:outputText value="#{aBean.dateOfAdmission}">
														<f:convertDateTime pattern="dd MMM yyyy" timeZone="#{preferences.timeZone.ID}" />
													</h:outputText>
												</rich:column>
												<rich:column>
													<f:facet name="header">CheckOut</f:facet>
													<h:outputText value="#{aBean.dateOfExit}">
														<f:convertDateTime pattern="dd MMM yyyy" timeZone="#{preferences.timeZone.ID}"/>
													</h:outputText>
													<h:outputText rendered="#{empty aBean.dateOfExit}" value="N/A"/>
												</rich:column>
												<rich:column>
													<f:facet name="header">Problem</f:facet>
													<h:outputText  value="#{aBean.medicalProblem}"	converter="#{medicalProblemConverter}"/>
												</rich:column>
												<rich:column>
													<f:facet name="header">Case Number</f:facet>
													<h:outputText  value="#{aBean.caseNo}"/>
												</rich:column>																																								
											</rich:dataTable>
											<rich:dataTable width="100%"  value="#{fn:asList(searchController.patient.attendents)}" var="aBean" align="center" style="text-align:left">
												<f:facet name="header">
													<h:outputText value="Attendents"/>													
												</f:facet>									
												<rich:column>
													<f:facet name="header">Name</f:facet>
													<h:outputText value="#{aBean.name} "/>
												</rich:column>																													
											</rich:dataTable>
											<a4j:commandLink onclick="return false;" id="ppat"/>
								</h:panelGrid>
			
			</rich:panel>
			 
			</h:form>
			
			
			    

	</ui:define>
</ui:composition>